const sm2 = require('sm-crypto').sm2;

function p(e) {
    var t = new Array
        , n = 0;
    for (var i in e)
        t[n] = i,
            n++;
    var r = [].concat(t).sort()
        , o = {};
    for (var a in r)
        o[r[a]] = e[r[a]];
    return o
}

const c = 'NMVFVILMKT13GEMD3BKPKCTBOQBPZR2P'

function v(e) {
    var t = [];
    for (var n in e)
        if (e.hasOwnProperty(n) && (e[n] || "".concat(e[n])))
            if ("data" === n) {
                var i = Object.assign({}, e[n]);
                for (var r in i) {
                    if ("number" != typeof i[r] && "boolean" != typeof i[r] || (i[r] = "" + i[r]),
                    Array.isArray(i[r]) && !i[r].length && delete i[r],
                    Array.isArray(i[r]) && i[r].length > 0)
                        for (var o = 0; o < i[r].length; o++)
                            i[r][o] = p(i[r][o]);
                    null != i[r] && i[r] || delete i[r]
                }
                var a = p(i);
                t.push("".concat(n, "=").concat(JSON.stringify(a)))
            } else
                t.push("".concat(n, "=").concat(e[n]));
    return t.push("key=".concat(c)),
        t.join("&")
}


params = {
    "appCode": "T98HPCGN5ZVVQBS8LZQNOAEXVI9GYHKQ",
    "data": {
        "addr": "",
        "medinsLvCode": "",
        "medinsName": "",
        "medinsTypeCode": "",
        "outMedOpenFlag": "",
        "pageNum": 6,
        "pageSize": 10,
        "queryDataSource": "es",
        "regnCode": "410100"
    },
    "encType": "SM4",
    "signType": "SM2",
    "timestamp": 1739615660,
    "version": "1.0.0"
}
var d = 'AJxKNdmspMaPGj+onJNoQ0cgWk2E3CYFWKBJhpcJrAtC'
var r = v(params)
    , a = sm2.doSignature(r, d, {
    hash: !0
})
signData = Buffer.from(a, "hex").toString("base64")
console.log(signData)
